package com.estar.integaration.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.estar.integaration.Mapper.ProductDbMapper;
import com.estar.integaration.Service.IProductDbService;
import com.estar.integaration.entity.ProductDb;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author YJL
 * @since 2021-11-18
 */
@Service
public class ProductDbServiceImpl extends ServiceImpl<ProductDbMapper, ProductDb> implements IProductDbService {

  @Autowired
  ProductDbMapper productDbMapper;

  @Override
  public void insert(ProductDb productDb) {
    productDbMapper.insert(productDb);
  }

  @Override
  public void deleteProductDbById(String id) {
    productDbMapper.deleteById(id);
  }

  @Override
  public ProductDb selectProductDbById(String id) {
    return productDbMapper.selectById(id);
  }

  @Override
  public List<ProductDb> selectByQueryWrapper(QueryWrapper wrapper) {
    return productDbMapper.selectList(wrapper);
  }

  @Override
  public List<ProductDb> selectNullDeliveryProductList() {
    List<ProductDb> productDbList = productDbMapper.selectList(null);

    return productDbList.stream().filter(p -> p.getProductDeliveryTime() == null).collect(Collectors.toList());

  }

  @Override
  public void updateProductDbById(ProductDb productDb) {
    productDbMapper.updateById(productDb);
  }

}
